using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace TidhiGanitam.DataModel
{
    public class DinamuRoutineItem
    {
        private Rasi m_Suryodayam;
        private Rasi m_Suryastamam;
        private int m_Year;
        DateTime m_Date;
        private RaviRoutineItem m_RaviRoutine;
        private Rasi m_MadyamaRavi;
        private Rasi m_DinaPramanam = new Rasi(Constants.DinaPramanam);
        private Rasi m_Dinardham = new Rasi(Constants.DinaPramanam/2);
        private Rasi m_RojuPramanamu ;
        private int m_SNo;
        private Rasi m_IyanamsamuValue;


        public Rasi Suryodayam
        {
            get { return m_Suryodayam; }
        }
        public Rasi Suryastamam
        {
            get { return m_Suryastamam; }
        }
        public int Bhagam
        {
            get { return m_SNo; }
        }
        public DateTime Date
        {
            get { return m_Date; }
        }
        public Rasi DinaPramanam
        {
            get { return m_DinaPramanam; }
        }
        public Rasi RojuPramanam
        {
            get
            { return m_RojuPramanamu; }
        }
        public Rasi Dinardhamu
        {
            get { return m_Dinardham; }
        }
        public Rasi Iyanamsamu
        {
            get
            { return m_IyanamsamuValue; }
        }
        public DinamuRoutineItem(int SNo, int Year, DateTime Date, Rasi IyanamsamuForYear, RaviRoutineItem RaviRoutine)
        {
            m_SNo = SNo;
            m_Year = Year;
            m_Date = Date;
            m_RaviRoutine = RaviRoutine;
            m_MadyamaRavi = new Rasi(RaviRoutine.MadyamaRavi);
            m_RojuPramanamu = new Rasi(Constants.RojuPramanam1[Convert.ToInt32(m_MadyamaRavi.Rasulu)]);
            m_IyanamsamuValue = new Rasi(IyanamsamuForYear);
        }
        public void Calculate()
        {
            //for the time being calculating for year 2008
            //later we should find a way to get iyanamsa values
            m_IyanamsamuValue += Constants.IyanamsaDinaGati ;

            m_MadyamaRavi += m_IyanamsamuValue;
            m_MadyamaRavi.Refresh();
            //Find out kranti part
            Rasi Kranti = Constants.GetRaviKrantiValue(m_MadyamaRavi);
            //Find out Charam
            int iKrantiIndex = (int)Kranti.Bhagalu;
            if (iKrantiIndex < 0) iKrantiIndex = 0;
            double dDiff = Constants.Akshamsa17Values[iKrantiIndex + 1] - Constants.Akshamsa17Values[iKrantiIndex];
            Rasi Charam = new Rasi(0, 0, Kranti.Liptalu, Kranti.Viliptalu);
            Charam = ((Rasi)(Charam * new Rasi(0, 0, 0, dDiff)));
            Charam += new Rasi(0, 0, 0, Constants.Akshamsa17Values[iKrantiIndex]);
            Charam = new Rasi(0, 0, Charam.Liptalu, Charam.Viliptalu);
            Charam *= 2;
            if (m_MadyamaRavi <= new Rasi(5, 29, 59, 59))
            {
                //Uttara Kranti
                m_DinaPramanam += Charam;
            }
            else
            {
                //Dakshina Kranti
                m_DinaPramanam -= Charam;

            }
            //Calculate dinardham
            m_Dinardham = ((Rasi)(m_DinaPramanam / 2));//.Round();
            //Convert the rasi to time
            Rasi TimeConst = m_Dinardham * 2 / 5;
            //Calculate suryodayamu
            m_Suryodayam = new Rasi(0, 0, 12, 0) - TimeConst;
            //Get the time adjustments for the particular date and rajahmundry
            double dblTimeAdjustments = Constants.GetTimeConstForDate(m_Date);
            //Make time adjustments
            m_Suryodayam += new Rasi(0, 0, 0, dblTimeAdjustments);
            m_Suryodayam += new Rasi(0, 0, 0, 3);//Adjustments for rajahmundry
            //Calculate suryastamam
            Rasi DinaPramanamInHrs = m_DinaPramanam * 2 / 5;
            m_Suryastamam = m_Suryodayam + DinaPramanamInHrs - new Rasi(0,0,12,0);
        }

    }
}
